<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>


<script>
  function ajaxAsync(methods="GET",url){
    return new Promise((resolve, reject) => {
      let xml = new XMLHttpRequest();
      xml.open(methods,url);
      xml.onreadystatechange = function (){
        if (this.readyState !== 4){
          return;
        }
        if (this.status === 200){
          resolve(this.response)
        }else {
          reject(new Error(this.statusText))
        }
      };
      xml.send();
    })
  }
  ajaxAsync('GET','./ajax.json').then(res=>{
    console.log('成功',JSON.parse(res).data)
  }).catch(err=>{
    console.log('失败', err);
  })
</script>
</body>
</html>